sr=48000
kr=4800
nchnls=2


    instr 1 
  kmask     linuxjoystick   0, 1
;;; this uses the first two axes on your joystick.
  kaxes     tab       0, 1
  kdbg      tab       kaxes+11, 1
  kf0       tab       kaxes+6, 1
  kf1       tab       kaxes+7, 1
  kf2       tab       kaxes+8, 1
  kf3       tab       kaxes+9, 1
  kx        tab       2, 1
  ky        tab       3, 1
  kx2       tab       4, 1
  ky2       tab       5, 1
  k_r1, ktheta1       cart2polar                  kx, ky
  k_rdiff1, kangdiff1 rotation                    kx, ky
  k_r2, ktheta2       cart2polar                  kx2, ky2
  k_rdiff2, kangdiff2 rotation                    kx2, ky2

  icps      =  (44100/sr)/(2/3)
  imaxovr   =  10000
  iphsdiv   =  2*$M_PI

  kfmr      ctrl7     1, 1, 0, (1/3)/32767
  kdurfac   ctrl7     1, 2, 65528, 4096
  kmindur   ctrl7     1, 12, 0.0001, 0.1
  kdens     ctrl7     1, 3, 1, 100
  kmindens  ctrl7     1, 13, 0, 20
  kpmdr     ctrl7     1, 4, 0.01, 1
  kfrpow    ctrl7     1, 6, -2, 2
  kprpow    ctrl7     1, 7, -2, 2
printf "kfmr %G\\nkdurfac %G\\nkmindur %G\\nkdens %G\\nkmindens %G\\nkpmdr %G\\nkfrpow %G\\nkprpow %G\\n\\n", kdbg, kfmr, kdurfac, kmindur, kdens, kmindens, kpmdr, kfrpow, kprpow
if kf0 != 1 kgoto dur1
  kfmd1     = (32767-k_r1)*kfmr
            kgoto     fm1
dur1:
  kdur1     =  (k_r1/kdurfac)+kmindur
fm1:
if kf1 != 1 kgoto dur2
  kfmd2     = (32767-k_r1)*kfmr
            kgoto     fm2
dur2:
  kdur2     =  (k_r2/kdurfac)+kmindur
fm2:
if kf2 != 1 kgoto cps1
  kpmd1     =  (kangdiff1/iphsdiv)*kpmdr
            kgoto     pmd1
cps1:
  kdens1     =  (kangdiff2/(2*$M_PI)+$M_PI)*kdens+kmindens
pmd1:
if kf3 != 1 kgoto cps2
  kpmd2     =  (kangdiff2/iphsdiv)*kpmdr
            kgoto     pmd2
cps2:
  kdens2     =  (kangdiff2/(2*$M_PI)+$M_PI)*kdens+kmindens
pmd2:
  kcps1     =  icps+(k_rdiff1/32767)
  kcps2     =  icps+(k_rdiff2/32767)

  iwfn      =  4
  kfn1      =  2
  kfn2      =  3
  kphs1     =  (ktheta1+$M_PI)/iphsdiv
  kphs2     =  (ktheta2+$M_PI)/iphsdiv
  agl       grain3    kcps1, kphs1, kfmd1, kpmd1, kdur1, kdens1, imaxovr, kfn1, iwfn, kfrpow, kprpow  
  agr       grain3    kcps2, kphs2, kfmd2, kpmd2, kdur2, kdens2, imaxovr, kfn2, iwfn, kfrpow, kprpow
  iampscale =  90/32767
            outs      agl*ampdb(k_r1*iampscale), agr*ampdb(k_r2*iampscale)
    endin
